package com.yanqu.road.server.logic.activity.condition.normal;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.task.args.ManorRankArgs;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseRankActivityCondition;

import java.math.BigInteger;
import java.util.Map;

/**
 * @author ：zfr
 * @date ：2021/6/29 10:11
 */
public class ManorOutPutRankCondition extends BaseRankActivityCondition {

    public ManorOutPutRankCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.ManorOutPutCountRank.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.ManorOutPutCountRank.getValue(), handle);
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        ManorRankArgs args = (ManorRankArgs) object;
        Map<Integer, Long> addMap = args.getAddMap();
        long totalValue = 0L;
        for (Map.Entry<Integer, Long> entry : addMap.entrySet()) {
            if (entry.getKey() == activityInfo.getActivityId()) {
                totalValue += entry.getValue();
            }
        }
        setValue(BigInteger.valueOf(totalValue));
        //重新生成排行榜
        rankChange();
    }
}
